<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="itcast" uri="http://itcast.cn/common/"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="description" content=""/>
<meta name="author" content=""/>

<title>查询修改用户信息</title>
<link href="<%=basePath%>css/bootstrap.min.css" rel="stylesheet"
	media="screen" />
<link href="<%=basePath%>css/bootstrap-datetimepicker.min.css"
	rel="stylesheet" media="screen" />
<!-- Bootstrap Core CSS -->
<link href="<%=basePath%>css/bootstrap.min.css" rel="stylesheet">

<!-- MetisMenu CSS -->
<link href="<%=basePath%>css/metisMenu.min.css" rel="stylesheet">

<!-- DataTables CSS -->
<link href="<%=basePath%>css/dataTables.bootstrap.css" rel="stylesheet">

<!-- Custom CSS -->
<link href="<%=basePath%>css/sb-admin-2.css" rel="stylesheet">

<!-- Custom Fonts -->
<link href="<%=basePath%>css/font-awesome.min.css" rel="stylesheet"
	type="text/css">
<link href="<%=basePath%>css/boot-crm.css" rel="stylesheet"
	type="text/css">

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body>

	<div id="wrapper">


		<!-- Navigation -->
		<nav class="navbar navbar-default navbar-static-top" role="navigation"
			style="margin-bottom: 0">
		<div class="navbar-header">
			<button type="button" class="navbar-toggle" data-toggle="collapse"
				data-target=".navbar-collapse">
				<span class="sr-only">Toggle navigation</span> <span
					class="icon-bar"></span> <span class="icon-bar"></span> <span
					class="icon-bar"></span>
			</button>
			<a class="navbar-brand" href="<%=basePath%>index.action">工单管理系统V1.0</a>
			<div class="navbar-brand">欢迎您：${sessionScope.user_login.username}</div>
		</div>
		<!-- /.navbar-header --> <!-- /.navbar-top-links -->

		<div class="navbar-default sidebar panel-collapse collapse in"
			role="navigation">
			<div class="sidebar-nav navbar-collapse">
				<ul class="nav" id="side-menu">
					<li><a href="#WorkOrderSetting"
						class="sidebar-nav navbar-collapse" data-toggle="collapse">&nbsp;&nbsp;
							<i class="fa fa-th-list fa-fw"></i> 工单管理
					</a></li>
					<ul id="WorkOrderSetting" class="nav nav-list collapse secondmenu">
						<!-- <li><a href="<%=basePath%>createWorkOrder.action">&nbsp;&nbsp;<i class="fa fa-edit fa-fw"></i> 新建工单</a></li> -->
						<li><a href="<%=basePath%>queryWorkOrder.action">&nbsp;&nbsp;<i
								class="fa fa-eye fa-fw"></i> 查询工单
						</a></li>
						<li><a href="<%=basePath%>addMissionOrder.action">&nbsp;&nbsp;<i
								class="fa fa-plus fa-fw"></i> 新建任务
						</a></li>
						<li><a href="<%=basePath%>queryMissionOrder.action">&nbsp;&nbsp;<i
								class="fa fa-folder-open fa-fw"></i> 查询任务
						</a></li>
						<li><a href="<%=basePath%>statistics.action">&nbsp;&nbsp;<i class="fa fa-line-chart fa-fw"></i> 统计数据</a></li>
					</ul>
					<li><a href="#customerSetting"
						class="sidebar-nav navbar-collapse" data-toggle="collapse">&nbsp;&nbsp;
							<i class="fa fa-user fa-fw"></i> 员工管理
					</a></li>
					<ul id="customerSetting" class="nav nav-list collapse secondmenu">
						<li><a href="<%=basePath%>register.action">&nbsp;&nbsp;<i
								class="fa fa-plus fa-fw"></i> 创建员工
						</a></li>
						<li><a href="<%=basePath%>queryUser.action">&nbsp;&nbsp;<i
								class="fa fa-edit fa-fw"></i> 查询员工
						</a></li>
						<!-- <li><a href="#">&nbsp;&nbsp;<i class="fa fa-edit fa-fw"></i> 密码修改</a></li> -->
					</ul>
					<li><a href="#quit" class="sidebar-nav navbar-collapse"
						data-toggle="collapse">&nbsp;&nbsp;&nbsp;<i
							class="fa fa-remove fa-fw"></i> 账号登出
					</a></li>
					<ul id="quit" class="nav nav-list collapse secondmenu">
						<li><a href="<%=basePath%>quit.action">&nbsp;&nbsp;<i
								class="fa fa-remove fa-fw"></i> 退出
						</a></li>
					</ul>

				</ul>
			</div>
			<!-- /.sidebar-collapse -->
		</div>
		<!-- /.navbar-static-side --> </nav>

		<div id="page-wrapper">
			<div class="row">
				<div class="col-lg-12">
					<h1 class="page-header">查询修改用户信息</h1>
				</div>
				<!-- /.col-lg-12 -->
			</div>
			<div class="row">
				<div class="col-lg-12">
					<div class="panel panel-default">
						<div class="panel-heading">员工信息列表</div>
						<!-- /.panel-heading -->
						<div class="table-responsive">
							<table class="table table-bordered table-striped">
								<thead>
									<tr>
										<th>序号</th>
										<th>工号</th>
										<th>注册日期</th>
										<th>姓名</th>
										<th>权限</th>
										<th>状态</th>
										<th>操作</th>
									</tr>
								</thead>

								<tbody>
									<c:forEach items="${list}" var="user">
										<tr>
											<td>${user.id}</td>
											<td>${user.uid}</td>
											<td>${user.create_date}</td>
											<td>${user.username}</td>
											<c:if test="${user.role=='manager'}">
												<td>管理员</td>
											</c:if>
											<c:if test="${user.role=='employee'}">
												<td>普通员工</td>
											</c:if>
											<c:if test="${user.state=='normal'}">
												<td>正常</td>
											</c:if>
											<c:if test="${user.state=='locked'}">
												<td>冻结</td>
											</c:if>
											<td>
												<a href="#" class="btn btn-primary btn-xs"
												data-toggle="modal" data-target="#userEditDialog"
												onclick="editUser(${user.id})">修改</a> 
												<a href="#"
												class="btn btn-danger btn-xs"
												onclick="deleteUser(${user.id})">删除</a>
											</td>
										</tr>
									</c:forEach>
								</tbody>
							</table>
						</div>
						<!-- /.panel-body -->
					</div>
					<!-- /.panel -->
				</div>
				<!-- /.col-lg-12 -->
			</div>

			<!-- 客户编辑对话框 -->
			<div class="modal fade" id="userEditDialog" tabindex="-1"
				role="dialog" aria-labelledby="myModalLabel">
				<div class="modal-dialog" role="document">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal"
								aria-label="Close">
								<span aria-hidden="true">&times;</span>
							</button>
							<h4 class="modal-title" id="myModalLabel">修改员工信息</h4>
						</div>
						<div class="modal-body">
							<form class="form-horizontal" id="edit_user_form">
								<input type="hidden" id="edit_id" name="id" />
								<div class="form-group">
									<label for="uid" class="col-sm-2 control-label">工号</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" id="edit_uid"
											placeholder="工号" name="uid" value="aaa" />
									</div>
								</div>
								<div class="form-group">
									<label for="username"
										class="col-sm-2 control-label">姓名</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" id="edit_username"
											placeholder="姓名" name="username" />
									</div>
								</div>
								<div class="form-group">
									<label for="password" class="col-sm-2 control-label">密码</label>
									<div class="col-sm-10">
										<input type="password" class="form-control" id="edit_password"
											placeholder="密码" name="password" />
									</div>
								</div>
								<div class="form-group">
									<label for="create_date" class="col-sm-2 control-label">注册日期</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" id="edit_create_date"
											placeholder="注册日期" name="create_date"/>
									</div>
								</div>
								<div class="form-group">
									<label for="role"
										class="col-sm-2 control-label">权限</label>
									<div class="col-sm-10">
										<select class="form-control" id="edit_role"
											name="role">
											<option value="employee" <c:if test="${user.role==employee}"> selected</c:if>>普通员工</option>
												<option value="manager"
													<c:if test="${user.role==manager}"> selected</c:if>>管理员</option>
											
										</select>
									</div>
								</div>
								<div class="form-group">
									<label for="state"
										class="col-sm-2 control-label">账号状态</label>
									<div class="col-sm-10">
										<select class="form-control" id="edit_state"
											name="state">
											<option value="normal" <c:if test="${user.state==normal}"> selected</c:if>>正常</option>
											<option value="locked" <c:if test="${user.state==locked}"> selected</c:if>>冻结</option>
										</select>
									</div>
								</div>
							</form>
						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default"
								data-dismiss="modal">关闭</button>
							<button type="button" class="btn btn-primary"
								onclick="updateUser()">保存修改</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

		<!-- jQuery -->
		<script src="<%=basePath%>js/jquery.min.js"></script>

		<!-- Bootstrap Core JavaScript -->
		<script src="<%=basePath%>js/bootstrap.min.js"></script>

		<!-- Metis Menu Plugin JavaScript -->
		<script src="<%=basePath%>js/metisMenu.min.js"></script>

		<!-- DataTables JavaScript -->
		<script src="<%=basePath%>js/jquery.dataTables.min.js"></script>
		<script src="<%=basePath%>js/dataTables.bootstrap.min.js"></script>

		<!-- Custom Theme JavaScript -->
		<script src="<%=basePath%>js/sb-admin-2.js"></script>
		<script type="text/javascript"
			src="<%=basePath%>js/jquery-1.8.3.min.js" charset="UTF-8"></script>
		<script type="text/javascript"
			src="<%=basePath%>js/bootstrap-datetimepicker.js" charset="UTF-8"></script>
		<script type="text/javascript"
			src="<%=basePath%>js/locales/bootstrap-datetimepicker.zh-CN.js"
			charset="UTF-8"></script>
		<script type="text/javascript"
			src="<%=basePath%>js/locales/bootstrap-datetimepicker.fr.js"
			charset="UTF-8"></script>
		<script type="text/javascript">
	function toIndex(){
		location.href="<%=basePath%>index.action";
		}
	function register(){
		var uid = $("#uid").val();
		var username = $("#username").val();
		var password = $("#password").val();
		if(username!=null && password!=null){
			
		$.ajax({
			type:"post",
			url:"<%=basePath%>registerPage.action",
			/* data:{"grammage":grammage,"gname":gname,"pname":pname,"specification":specification,
				"address":address,"m_count":m_count}, */
			data:$('#registerform').serialize(),
			success:function(data) {
				if(data.trim()=="ok")   
				{  
					if(confirm(" 注册成功，是否继续")){
						location.href="<%=basePath%>register.action";
							}
						} else {
							alert("注册失败 ");
						}
					},
					error : function() {
						alert(" 注册失败 ");
					}
				});
			}
			else{
				alert("用户名和密码不能为空 ");
			}
		}
	
	function editUser(id) {
		$.ajax({
			type:"post",
			url:"<%=basePath%>editUser.action",
			data:{"id":id},
			success:function(data) {
				
				$("#edit_id").val(data.id);
				$("#edit_uid").val(data.uid);
				$("#edit_username").val(data.username);
				$("#edit_password").val(data.password);
				$("#edit_create_date").val(data.create_date);
				$("#edit_role").val(data.role);
				$("#edit_state").val(data.state);
			},
			error:function(){
				alert(data.uid);
			}
		});
	}
	
	function updateUser() {
		$.post("<%=basePath%>updateUser.action",$("#edit_user_form").serialize(),function(data){
			alert("员工信息更新成功！");
			window.location.reload();
		});
	}
	
	function deleteUser(id) {
		if(confirm('确实要删除该员工吗? ')) {
			$.post("<%=basePath%>deleteUser.action",{"id":id},function(data){
				alert(" 员工删除更新成功！");
				window.location.reload();
			});
		}
	}
	</script>
</body>

</html>
